import pygame,pygame.image,pygame.constants

import sys

msg ="""\nError not correct arguments
Utility that redims a image to one column instead of manny
usage:
    %s input_image outputname tile_with tile_height
"""%sys.argv[0]

if len(sys.argv) != 5:
    sys.stderr.write(msg)
    sys.exit()

tile_w = int(sys.argv[3])
tile_h = int(sys.argv[4])
i_pic = pygame.image.load(sys.argv[1]) 
i_rect = i_pic.get_rect()

iDim = (int (i_rect[2]/tile_w),int (i_rect[3]/tile_h))
oDim = (1,iDim[0]*iDim[1])
print "old dim %d:%d" % (iDim[0],iDim[1])
print "new dim %d:%d" % (oDim[0],oDim[1])

o_pic = pygame.Surface((oDim[0]*tile_w,oDim[1]*tile_h), flags=i_pic.get_flags)
s_rect = pygame.Rect(0,0,tile_w,tile_h)
d_rect = pygame.Rect(0,0,tile_w,tile_h)

for x in range(iDim[0]):
    s_rect.top = 0
    for y in range(iDim[1]):
        o_pic.blit(i_pic,d_rect,s_rect)
        d_rect.move_ip(0,tile_h)
        s_rect.move_ip(0,tile_h)
    s_rect.move_ip(tile_w,0)

pygame.image.save(o_pic,sys.argv[2]) 
print "Done!"